package com.panda.multiple.tenant3.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panda.multiple.tenant3.config.MyTenantLineHandler;
import com.panda.multiple.tenant3.dao.UserMapper;
import com.panda.multiple.tenant3.domain.po.User;
import com.panda.multiple.tenant3.domain.vo.UserVO;
import com.panda.multiple.tenant3.service.TenantService;
import com.panda.multiple.tenant3.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    private UserMapper userMapper;

    @Resource
    private TenantService tenantService;

    @Override
    public List<User> getValidUsers() {
        MyTenantLineHandler.setTenantId(tenantService.getTenantInfoForLoginUser());
        return getBaseMapper().selectList(null);
    }

    @Override
    public Integer updateById(UserVO userVO) {
        MyTenantLineHandler.setTenantId(tenantService.getTenantInfoForLoginUser());
        User user = new User();
        BeanUtils.copyProperties(userVO, user);
        return getBaseMapper().updateById(user);
    }
}
